package com.swp.oa.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import com.swp.oa.comomn.MySQLDatabaseBackUpOption;

public class MySQLBackUpTimerTask extends TimerTask{

	@Override
	public void run() {
		String fileName = DateUtil.getDateFormat(new Date()) + ".sql";
		MySQLBackUpUtil.exportDatabaseTool(MySQLDatabaseBackUpOption.getBinPath(), 
    									   MySQLDatabaseBackUpOption.getHostIP(), 
    									   MySQLDatabaseBackUpOption.getUserName(), 
    									   MySQLDatabaseBackUpOption.getPassWord(), 
    									   MySQLDatabaseBackUpOption.getSavePath(), 
    									   fileName, 
    									   MySQLDatabaseBackUpOption.getDatabaseName());
	}
//	public static boolean backUp(){
//		TimerTask task = new TimerTask() {
//            @Override
//            public void run() {
//            	String fileName = DateUtil.getDateFormat(new Date()) + ".sql";
//            	MySQLBackUpTimerTask.exportDatabaseTool(MySQLDatabaseBackUpOption.getBinPath(), 
//            									   MySQLDatabaseBackUpOption.getHostIP(), 
//            									   MySQLDatabaseBackUpOption.getUserName(), 
//            									   MySQLDatabaseBackUpOption.getPassWord(), 
//            									   MySQLDatabaseBackUpOption.getSavePath(), 
//            									   fileName, 
//            									   MySQLDatabaseBackUpOption.getDatabaseName());
//            }
//        };
//        //设置执行时间
//        Calendar calendar = Calendar.getInstance();
//        int year = calendar.get(Calendar.YEAR);
//        int month = calendar.get(Calendar.MONTH);
//        int day = calendar.get(Calendar.DAY_OF_MONTH);//每天
//        //定制每天的21:09:00执行，
//        calendar.set(year, month, day, 16, 56, 00);
//        Date date = calendar.getTime();
//        Timer timer = new Timer();
////        System.out.println(date);
//        
////        int period = 2 * 1000;
//        //每天的date时刻执行task，每隔2秒重复执行
////        timer.schedule(task, date, period);
//        //每天的date时刻执行task, 仅执行一次
//        timer.schedule(task, date);
//		return true;
//	}
	
}
